package com.ganxiang.ximenhong.base;

import android.annotation.TargetApi;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.ganxiang.autolayoutlibary.AutoLayoutActivity;
import com.ganxiang.statusbarlobraty.StatusBarCompat;
import com.ganxiang.ximenhong.R;
import com.ganxiang.ximenhong.model.TaskListener;
import com.ganxiang.ximenhong.model.TaskType;

/**
 * Created by Administrator on 2016/9/12 0012.
 */
public class BaseActivity extends AutoLayoutActivity implements TaskListener {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        XiMenHongApplication.getIntanst().addActivity(this);



//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//            setTranslucentStatus(this, true);
//        }
//        SystemBarTintManager tintManager = new SystemBarTintManager(this);
//
//        tintManager.setStatusBarTintEnabled(true); // 使用颜色资源
//
//        tintManager.setStatusBarTintResource(R.color.themeColor);

        StatusBarCompat.setStatusBarColor(this, Color.parseColor("#F23030"));

    }

    @TargetApi(19)
    private static void setTranslucentStatus(Activity activity, boolean on) {
        Window win = activity.getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if (on) {
            winParams.flags |= bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);

    }

    public void setTitleBar(int stringId){
        View backIv = findViewById(R.id.iv_back);
        if(backIv != null){
            backIv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    finish();
                }
            });
        }
        TextView titleTv = (TextView) findViewById(R.id.tv_title);
        if (titleTv != null){
            titleTv.setText(getString(stringId));
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        XiMenHongApplication.getIntanst().removeActivity(this);
    }

    @Override
    public void taskStarted(TaskType type) {

    }

    @Override
    public void taskProgress(TaskType type, int progress, int total) {

    }

    @Override
    public void taskFinished(TaskType type, Object result) {

    }

    @Override
    public void taskFinished(TaskType type, Object result, Object tag) {

    }

    @Override
    public void taskIsCanceled(TaskType type) {

    }
}
